package com.hyx.bookManager.service.impl;

import com.hyx.bookManager.domain.common.CommonResult;
import com.hyx.bookManager.domain.po.Tag;
import com.hyx.bookManager.mapper.TagMapper;
import com.hyx.bookManager.service.TagService;
import com.hyx.bookManager.utils.Snowflake;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName TagServiceImpl
 * @Description TODO
 * @Author 黄乙轩
 * @Date 2021/6/18 21:28
 * @Version 1.0
 **/
@Service
public class TagServiceImpl implements TagService {

    @Autowired
    private TagMapper tagMapper;

    @Autowired
    private Snowflake snowflake;

    @Override
    public CommonResult getAllTag() {
        List<Tag> tags = tagMapper.getAllTag();
        return CommonResult.success("查询成功",tags);
    }

    @Override
    public CommonResult insertTag(String tagName) {
        Long id = snowflake.nextId();
        boolean flag = tagMapper.insertTag(tagName, id);
        if(flag){
            return CommonResult.success("插入成功");
        }else{
            return CommonResult.fail();
        }
    }
}
